package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.adapter.ImageCommonRvV2Adapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.HandlerBatteryDetailEntity
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler

class HandlerBatteryDetailAdapter(private val context: AppCompatActivity, private val mList: List<HandlerBatteryDetailEntity.DataBean.ItemsBean>) : BaseEmptyRecyclerViewAdapterV2(context, mList) {

    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_handler_battery_detail_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.moduleCount.text = data.moduleCount.handlerNull()
            holder.batteryName.text = data.batteryName.noDataHandler()
            holder.batteryCode.text = data.batteryCode.noDataHandler()
            holder.batterySelfCode.text = data.batterySelfCode.noDataHandler()
            holder.count.text = data.count.noDataHandler()
            holder.weight.text = data.weight.noDataHandler()
            holder.capacityAh.text = data.capacityAh.noDataHandler()
            holder.capacityKwh.text = data.capacityKwh.noDataHandler()
            holder.voltage.text = data.voltage.noDataHandler()
            val status = when (data.status) {
                1 -> "待入库"
                2 -> "已拆解"
                3 -> "已出库"
                4 -> "拆解中"
                else -> "暂无数据"
            }
            holder.status.text = status
            val enterMode = when (data.enterMode) {
                1 -> "整车电池"
                2 -> "散件"
                3 -> "电池拆解"
                else -> "暂无数据"
            }
            holder.enterMode.text = enterMode

            val batteryType = when (data.batteryType) {
                1 -> "电池包"
                2 -> "模组"
                3 -> "电芯"
                else -> "暂无数据"
            }
            holder.batteryType.text = batteryType
            holder.mNewBattery.visibility = if (data.child == null) View.GONE else View.VISIBLE

            if (data.picUrls == null) {

            } else {
                if (data.picUrls!!.isEmpty()) {
                    holder.mImageTV.visibility = View.GONE
                    holder.mImageRV.visibility = View.GONE
                } else {
                    holder.mImageTV.visibility = View.VISIBLE
                    holder.mImageRV.visibility = View.VISIBLE
                    holder.mImageRV.adapter = ImageCommonRvV2Adapter(context, data.picUrls!!)
                    holder.mImageRV.layoutManager = GridLayoutManager(context, 3, LinearLayoutManager.VERTICAL, false)
                }
            }
        }
    }


    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val moduleCount: TextView = view.findViewById(R.id.moduleCount)
        val batteryName: TextView = view.findViewById(R.id.batteryName)
        val batteryCode: TextView = view.findViewById(R.id.batteryCode)
        val batterySelfCode: TextView = view.findViewById(R.id.batterySelfCode)
        val count: TextView = view.findViewById(R.id.count)
        val weight: TextView = view.findViewById(R.id.weight)
        val capacityAh: TextView = view.findViewById(R.id.capacityAh)
        val capacityKwh: TextView = view.findViewById(R.id.capacityKwh)
        val voltage: TextView = view.findViewById(R.id.voltage)
        val status: TextView = view.findViewById(R.id.status)
        val batteryType: TextView = view.findViewById(R.id.batteryType)
        val enterMode: TextView = view.findViewById(R.id.enterMode)
        val mNewBattery: TextView = view.findViewById(R.id.mNewBattery)
        val mImageTV: TextView = view.findViewById(R.id.mImageTV)
        val mImageRV: RecyclerView = view.findViewById(R.id.mImageRV)
    }
}